package com.homegoods.shoppingcar;

import com.homegoods.classify.model.Constant;
//import com.homegoods.orderinfodetail.bean.ShoppingOrderdetail; //del shibo.zheng
import com.homegoods.resource.HomeGoodsApp;
import com.homegoods.shoppingcar.model.ShoppingCartBean;
import com.network.retrofit_rx.Api.ActionSubscriber;
import com.network.retrofit_rx.Api.CommandImpl;
import com.network.retrofit_rx.Api.HttpManager;

import org.json.JSONObject;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

public class ShoppingApiUtils {

    /**
     * 获取购物车列表
     *【043】原生：购物车：详情
     *
     * /amapi/SimplePlanCmd.aspx?cmd=ShoppingCart
     */
    public static Observable<List<ShoppingCartBean>> getShoppingList() {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "ShoppingCart")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsondata")
                .setObject(false)
                .setClass(ShoppingCartBean.class)
                .create();
          return HttpManager.getInstance().getObservable(command);
    }

    /**
     * 获取购物车列表
     *
     * @param error cmd=Modification   //方法名
     *              odata=jsonlist     //数据输出方式
     *              type=4             //type固定传4，不能传别的
     *              sid=999            //购物车的sid
     */
    public static void deleteShopping(String sid, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "Modification")
                .addParams("type", "4")
                .addParams("sid", sid)
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }
}
